<!DOCTYPE html>
<html class=" js csstransforms3d"><head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>往期内容</title>
	<link rel="stylesheet" href="css/base.css">
	<link rel="stylesheet" href="css/page.css">
	<!--[if lte IE 8]>
	<link href="css/ie8.css" rel="stylesheet" type="text/css"/>
	<![endif]-->
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/main.js"></script>
	<script type="text/javascript" src="js/modernizr.js"></script>
	<script type="text/javascript" src="js/PagingManage.js"></script>
	<!--[if IE]>
	<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
	<![endif]-->
</head>

<body style="background: #f6f5fa;">

	<!--content S-->
	<div class="super-content RightMain" id="RightMain">
		
		<!--header-->
		<div class="superCtab">
			<div class="ctab-title clearfix"><h3>往期内容</h3></div>
			
			<div class="ctab-Main">
				
				<div class="ctab-Mian-cont">
					<div class="Mian-cont-btn clearfix">
						<div class="operateBtn">
							<a href="reviewAdd" class="greenbtn publish">添加内容</a>
						</div>
						<div class="searchBar">
							<input type="text" id="keywords" value="" class="form-control srhTxt" placeholder="输入标题关键字搜索">
							<input type="button" class="srhBtn" value="" onclick="searchReviews();">
						</div>
					</div>
					
					<div class="Mian-cont-wrap">
						<div class="defaultTab-T">
							<table border="0" cellspacing="0" cellpadding="0" class="defaultTable">
								<tbody><tr><th class="t_1">内容标题</th><th class="t_2">图片预览</th><th class="t_3">是否有效</th><th class="t_4">操作</th></tr>
							</tbody></table>
						</div>
						<table border="0" cellspacing="0" cellpadding="0" class="defaultTable defaultTable2">
							<tbody id = "reviewList">
							
						</tbody></table>
						<!--pages S-->
						<div class="pageSelect"  id="complete">
						</div>
						<!--pages E-->
					</div>
				
				</div>
			</div>
		</div>
		<!--main-->
	</div>
</body>
</html>
<script>
    var pageSize = 10;
    $(function(){
        this.getReviews(1,pageSize,'');
    }.bind(this))

    function getReviews(pageNo,pageSize,keyWords) {
        var review = new Review(pageNo,pageSize,keyWords);
        $.ajax({
            type: 'POST',
            url: '/getReviews',
            data: review,
            dataType:'json',
            success:function(data, status){
                this.PagingManage($('#complete'),data.total, data.pageSize, data.pageNum,data.pages);
                var reviews = data.list;
                let reviewsHtml = '';
                for(var i =0 ;i<reviews.length;i++){
                    reviewsHtml += 	'<tr><td class="t_1">'+reviews[i].title+'</td><td class="t_2"  style="table-layout:fixed;word-wrap:break-word;word-break:break-all;"><img src="'+reviews[i].fileSrc+'" style="height:60px; ">'+'</img></td>' +
                        '<td class="t_3">'+this.isDisplay(reviews[i].stateType)+'</td><td class="t_4"><div class="btn">' +
                        '<a href="reviewAdd?id=' +reviews[i].reviewId+ '" class="modify">修改</a>' +
                        '<a href="javascript:;" class="delete" onclick="deleteReview(' +reviews[i].reviewId+ ')">删除</a></div></td></tr>';
                }
                document.getElementById("reviewList").innerHTML = reviewsHtml;
            }.bind(this),
            error:function(err, status){
            }});
    }
    function Review(pageNo,pageSize,keywords){
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.keywords = keywords;
    }
    function switchPage(divId, page) {
        this.getReviews(page,pageSize,$('#keywords').val());
    }
    function searchReviews() {
        this.getReviews(1,pageSize,$('#keywords').val());
    }

    function deleteReview(id) {
        var r=confirm("确认要删除该内容吗？");
        if (r==true){
            $.ajax({
                type: 'POST',
                url: '/deleteReview',
                data: {"id":id},
                dataType:'json',
                success:function(data, status){
                    this.getReviews(1,pageSize,$('#keywords').val());
                }.bind(this),
                error:function(err, status){
                }});
        }
    }
    function isDisplay(stateType) {
		if(stateType == 1){
		    return "有效";
		}else{
		    return "无效";
		}
    }
</script>